/*
	Copyright 2008 Marco Mustapic
	
    This file is part of Agilar GWT Widgets.

    Agilar GWT Widgets is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Agilar GWT Widgets is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Agilar GWT Widgets.  If not, see <http://www.gnu.org/licenses/>.
*/

package org.agilar.gwt.client;

import org.agilar.gwt.colorpicker.ColorPicker;
import org.agilar.gwt.sortabletable.PageIndex;
import org.agilar.gwt.sortabletable.PagedTableModel;
import org.agilar.gwt.sortabletable.SortableTable;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.RootPanel;

public class TestWidgets implements EntryPoint
{	
	public void onModuleLoad()
	{
		/*
		SimpleTableModel model = new SimpleTableModel(4, 3);
		
		model.setColumnName(0, "Strings");
		model.setColumnName(1, "Ints");
		model.setColumnName(2, "Integers");
		
		model.set(0, 0, "pizza");
		model.set(1, 0, "cangrejo");
		model.set(2, 0, "rinoceronte");
		model.set(3, 0, "nylon");

		model.set(0, 1, new Integer(17));
		model.set(1, 1, new Integer(84));
		model.set(2, 1, new Integer(77));
		model.set(3, 1, new Integer(15));
		
		model.set(0, 2, new Button("button 1"));
		model.set(1, 2, new Button("button 2"));
		model.set(2, 2, new Button("button 3"));
		model.set(3, 2, new Button("button 4"));
		
		final SortableTable table = new SortableTable(3);
		table.setModel(model);
		table.setDataFormatter(1, new DataFormatter<Integer>()
				{
					public String format(Integer value)
					{
						return "#"+value;
					}
			
				});
		RootPanel.get().add(table);
		
		Button button = new Button("reduce");
		button.addClickListener(new ClickListener()
		{
			public void onClick(Widget sender)
			{
				SimpleTableModel model = new SimpleTableModel(3, 1);
				model.setColumnName(0, "char");
				model.set(0, 0, "a");
				model.set(1, 0, "b");
				model.set(2, 0, "c");
				table.setModel(model);
			}
		});

		RootPanel.get().add(button);

		button = new Button("expand");
		button.addClickListener(new ClickListener()
		{
			public void onClick(Widget sender)
			{
				SimpleTableModel model = new SimpleTableModel(4, 3);
				model.setColumnAsSortable(0, new Comparator<String>()
						{
							public int compare(String o1, String o2)
							{
								return o1.compareTo(o2);
							}
						});
				
				model.setColumnName(0, "Strings");
				model.setColumnName(1, "Ints");
				model.setColumnName(2, "Integers");
				
				model.set(0, 0, "pizza");
				model.set(1, 0, "cangrejo");
				model.set(2, 0, "rinoceronte");
				model.set(3, 0, "nylon");

				model.set(0, 1, "17");
				model.set(1, 1, "84");
				model.set(2, 1, "77");
				model.set(3, 1, "15");
				
				model.set(0, 2, new Button("button 1"));
				model.set(1, 2, new Button("button 2"));
				model.set(2, 2, new Button("button 3"));
				model.set(3, 2, new Button("button 4"));

				table.setModel(model);
			}
		});
		RootPanel.get().add(button);
*/
		Grid grid = new Grid(3, 2);
		grid.setText(0, 0, "User-closed");
		grid.setWidget(0, 1, new ColorPicker("ffffff", false));
		grid.setText(1, 0, "Auto close");
		grid.setWidget(1, 1, new ColorPicker("ff0000", true));
		grid.setText(2, 0, "No links");
		grid.setWidget(2, 1, new ColorPicker("ff0000", false, true));
		RootPanel.get().add(grid);
		
		final PagedTableModel pagedModel = new PagedTableModel(3, 2, new SamplePagedTableModel());
		pagedModel.setColumnName(0, "char");
		pagedModel.setColumnName(1, "int");
		pagedModel.setColumnName(2, "3");
		SortableTable pagedTable = new SortableTable(3);
		pagedTable.setAscendingImage(new Image("up.png"));
		pagedTable.setDescendingImage(new Image("down.png"));
		pagedModel.setColumnSortable(1, false);
		RootPanel.get().add(pagedTable);
		pagedTable.setModel(pagedModel);
		pagedTable.sort(0, true);
		
		PageIndex widget = new PageIndex();
		widget.setModel(pagedModel);
		
		RootPanel.get().add(widget);
	}
}
